package org.example.basic.day06;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.function.Consumer;

/**
 * @author 清倌
 */
public class Demo04lambda操作集合 {
    public static void main(String[] args) {
        List<String> list = List.of("张三","lisi","王五");

        System.out.println("匿名内部类-----------------");
        list.forEach(new Consumer<String>() {
            @Override
            public void accept(String s) {
                System.out.println( s);
            }
        });
        //lambda表达式迭代集合
        System.out.println("lambda表达式-----------------");
        list.forEach((s)->{
            System.out.println(s);
        });
        System.out.println("方法引用-----------------");
        list.forEach(System.out::println);



        List<Layer> list1=new ArrayList<>();
        list1.add(new Layer("张三",18));
        list1.add(new Layer("lisi",19));
        list1.add(new Layer("王五",20));
        list1.forEach(layer -> {
            layer.setAge(layer.getAge()+1);
            System.out.println(layer);
        });

        Map<Integer, String> map = Map.of(1,"张三",2,"lisi",3,"王五");
        map.forEach((key,value)->{
            System.out.println(key+"--"+value);
        });
    }
}

@Data
@AllArgsConstructor
@NoArgsConstructor
class Layer{
    private String name;
    private int age;
}
